package com.czk.service;

import com.czk.pojo.Calculation;
import com.czk.pojo.CreditCardApplyInfo;
import org.kie.api.KieBase;
import org.kie.api.runtime.KieSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/8/24 22:43
 */
@Service
public class RuleService {
    @Autowired
    private KieBase kieBase;

    public void rule() {
        KieSession kieSession = kieBase.newKieSession();
        kieSession.fireAllRules();
        kieSession.dispose();
    }

    /**
     * 计算个人所得税
     *
     * @param calculation
     * @return
     */
    public Calculation calculate(Calculation calculation) {
        KieSession kieSession = kieBase.newKieSession();
        // 加入工作内存
        kieSession.insert(calculation);
        // 执行
        kieSession.fireAllRules();
        // 释放
        kieSession.dispose();
        return calculation;
    }

    /**
     * 计算性用卡
     * @param creditCardApplyInfo
     * @return
     */
    public CreditCardApplyInfo cardApplyInfo(CreditCardApplyInfo creditCardApplyInfo) {
        KieSession kieSession = kieBase.newKieSession();
        kieSession.insert(creditCardApplyInfo);
        kieSession.fireAllRules();
        kieSession.dispose();
        return creditCardApplyInfo;
    }
}
